﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>@Model.DBName 数据库文档_v1.0</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
            border: 0;
            outline: 0;
            font-weight: inherit;
            font-style: inherit;
            font-family: inherit;
            vertical-align: baseline;
        }

        body {
            line-height: 1;
            color: #000;
            background: #fff;
            width: 100%;
            font: 14px "Cascadia Code","lucida console","Consolas",'Microsoft YaHei',"Helvetica Neue", Helvetica, Arial, sans-serif;
            -webkit-text-size-adjust: 100%;
        }

        ol,
        ul {
            list-style: none;
        }

        table {
            border-collapse: separate;
            border-spacing: 0;
            vertical-align: middle;
        }

        th,
        td {
            text-align: center;
            vertical-align: middle;
            border-right: 1px solid #ddd;
            border-bottom: 1px solid #ddd;
        }

        a img {
            border: none;
        }

        body:before,
        body:after {
            content: "";
            display: table;
        }

        body:after {
            clear: both;
        }

        .outer {
            margin: 0 auto;
        }

        .outer:before,
        .outer:after {
            content: "";
            display: table;
        }

        .outer:after {
            clear: both;
        }

        .inner {
            display: inline;
            float: left;
            width: 100%;
        }

        #header {
            background: #fff;
            border-bottom: 1px solid #ccc;
            font-family: Lato, "Cascadia Code","lucida console","Consolas",'Microsoft YaHei',"Helvetica Neue", Helvetica, Arial, sans-serif;
            padding-top: 30px;
            padding-bottom: 30px;
            position: relative;
        }

        #logo-wrap {
            text-align: center;
            position: relative;
        }

        #logo-wrap {
            float: left;
        }

        #page-title {
            color: #555;
            font: 300 20px Lato, "Cascadia Code","lucida console","Consolas",'Microsoft YaHei',"Helvetica Neue", Helvetica, Arial, sans-serif;
            text-shadow: 1px 0 #eee;
            line-height: 1em;
            text-align: center;
        }

        .page-content {
            display: inline;
        }

        .page-entry {
            line-height: 1.6em;
            color: #444;
        }

        .page-entry p {
            white-space: pre-wrap;
        }

        .page-entry p,
        .page-entry ol,
        .page-entry ul,
        .page-entry dl,
        .page-entry table,
        .page-entry blockquote,
        .page-entry iframe,
        .page-entry .highlight {
            line-height: 1.9em;
            margin: 1.6em 0;
        }

        .page-entry td p {
            margin: 0.1em 0;
        }

        .page-entry h1 {
            font-size: 2em;
        }

        .page-entry h2 {
            font-size: 1.5em;
        }

        .page-entry h3 {
            font-size: 1.3em;
        }

        .page-entry h1,
        .page-entry h2,
        .page-entry h3,
        .page-entry h4,
        .page-entry h5,
        .page-entry h6 {
            line-height: 1em;
            font-weight: bold;
            margin: 1em 0;
        }

        .page-entry a {
            color: #33CCFF;
            text-decoration: none;
        }

        .page-entry a:hover {
            color: #33CCFF;
            border-color: #33CCFF;
            text-decoration: none;
        }

        .page-entry strong {
            font-weight: bold;
        }

        .page-entry table {
            width: 100%;
            border-top: 1px solid #ddd;
            border-left: 1px solid #ddd;
        }

        .page-entry table th {
            font-weight: bold;
            background: #eee;
        }

        .page-entry table th,
        .page-entry table td {
            padding: 5px 15px;
        }

        #page-footer {
            border-top: 1px solid #ddd;
            color: #999;
            padding: 1em 0 30px;
            text-align: center;
        }

        #page-footer:before,
        #page-footer:after {
            content: "";
            display: table;
        }

        #page-footer:after {
            clear: both;
        }

        #page-footer-updated {
            font-size: 0.9em;
            display: none;
        }

        #page-footer-updated {
            display: inline;
        }

        #page-footer-prev,
        #page-footer-next {
            font-family: Lato, "Cascadia Code","lucida console","Consolas",'Microsoft YaHei',"Helvetica Neue", Helvetica, Arial, sans-serif;
            font-size: 1em;
            color: #33CCFF;
            font-weight: bold;
            text-transform: uppercase;
            text-decoration: none;
        }

        #page-footer-prev {
            float: left;
        }

        #page-footer-prev:before {
            content: "\f060";
            padding-right: 10px;
        }

        #page-footer-next {
            float: right;
        }

        #page-footer-next:after {
            content: "\f061";
            padding-left: 10px;
        }

        #page-mobile-menu {
            width: 100%;
            margin: 30px 0 0;
            display: none;
        }

        #sidebar {
            font-family: Lato, "Cascadia Code","lucida console","Consolas",'Microsoft YaHei',"Helvetica Neue", Helvetica, Arial, sans-serif;
            padding: 0px;
            position: fixed;
            max-height: 740px;
            display: block;
            float: left;
            width: 17%;
            margin: 0;
            overflow-x: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow-y: auto;
        }

        .sidebar-title {
            display: block;
            color: #666;
            position: relative;
            padding-left: 20px;
            font-size: 102%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .sidebar-title:before {
            content: "";
            width: 8px;
            height: 8px;
            background: #666;
            -webkit-border-radius: 50%;
            border-radius: 50%;
            position: absolute;
            top: 7px;
            left: 0;
        }

        .sidebar-link {
            color: #666;
            text-decoration: none;
            display: block;
            font-weight: 300;
            padding: 5px 15px;
            border-left: 2px solid #ddd;
            margin-left: 3px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .sidebar-link:hover,
        .sidebar-link.current {
            color: #33CCFF;
            border-color: #33CCFF;
        }

        .sidebar-link.current {
            font-weight: bold;
            border-left-color: #33CCFF;
        }

        #footer {
            padding: 30px 0;
            font-family: Lato, "Cascadia Code","lucida console","Consolas",'Microsoft YaHei',"Helvetica Neue", Helvetica, Arial, sans-serif;
            color: #999;
            line-height: 1.5;
            border-top: 1px solid #ccc;
            text-align: center;
            margin-top: 10px;
        }

        #footer {
            text-align: center;
        }

        #footer-copyright {
            float: center;
        }

        #footer-copyright a {
            color: #777;
            text-decoration: none;
        }

        #footer-copyright a:hover {
            text-decoration: underline;
            color: #33CCFF;
        }


        #footer-links {
            float: right;
            margin-right: -10px;
        }

        .footer-link {
            text-decoration: none;
            width: 30px;
            height: 30px;
            font-size: 30px;
            line-height: 30px;
            display: inline-block;
            text-align: center;
            color: #999;
            margin: 0 10px;
            -webkit-transition: color 0.2s;
            -moz-transition: color 0.2s;
            -ms-transition: color 0.2s;
            transition: color 0.2s;
        }

        .footer-link:hover {
            color: #33CCFF;
        }

        .footer-link span {
            display: none;
        }

        #footer-link-twitter:before {
            content: "\f099";
        }

        #footer-link-github:before {
            content: "\f113";
        }

        .version_s {
            margin-left: 10px;
        }

        .clear {
            clear: both;
        }

        .outer {
            width: 95%;
            padding: 0 25px;
        }

        .page-content {
            width: 60%;
            display: inline-block;
            margin: 0 auto;
            margin-left: 30%;
        }

        #main-nav {
            display: block;
        }

        .version_s {
            display: inline;
        }

        .tab-struct caption {
            margin: 10px auto;
            color: #555;
            font: 300 18px Lato, "Cascadia Code","lucida console","Consolas",'Microsoft YaHei',"Helvetica Neue", Helvetica, Arial, sans-serif;
            text-shadow: 1px 0 #eee;
            line-height: 1em;
            text-align: center;
        }

        #dir .tab-struct tr td:first-child {
            width: 200px;
        }

        pre {
            border: 1px solid #ddd;
        }

        .snippet .page-entry {
            margin: 20px 0;
        }

        .other-bg-color {
            background-color: #fff;
        }

        .check-bg-color {
            background-color: #E6E6FA;
        }

        /**返回置顶**/
        #goto_top {
            display: none;
            position: fixed;
            bottom: 90px;
            right: 25px;
            width: 44px;
            z-index: 1999;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            align-content: center;
            box-shadow: 0 2px 4px 0 rgba(0,0,0,.05);
            background-color: #fff;
            text-align: center;
            height: 44px;
            cursor: pointer;
            border: 1px solid #e0e0e0;
        }

        #goto_top img {
            display: block;
            width: 22px;
            height: auto;
            margin: auto 0;
        }

        #goto_top .show-txt {
            display: none;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            align-content: center;
            font-size: 12px;
            line-height: 14px;
            background-color: #33CCFF;
            color: #fff;
            text-align: center;
            width: 100%;
            height: 100%;
        }
    </style>
    <style>
        pre code.hljs {
            display: block;
            overflow-x: auto;
            padding: 1em
        }

        code.hljs {
            padding: 3px 5px
        }

        .hljs {
            background: #fff;
            color: #000
        }

        .hljs-comment, .hljs-quote, .hljs-variable {
            color: green
        }

        .hljs-built_in, .hljs-keyword, .hljs-name, .hljs-selector-tag, .hljs-tag {
            color: #00f
        }

        .hljs-addition, .hljs-attribute, .hljs-literal, .hljs-section, .hljs-string, .hljs-template-tag, .hljs-template-variable, .hljs-title, .hljs-type {
            color: #a31515
        }

        .hljs-deletion, .hljs-meta, .hljs-selector-attr, .hljs-selector-pseudo {
            color: #2b91af
        }

        .hljs-doctag {
            color: grey
        }

        .hljs-attr {
            color: red
        }

        .hljs-bullet, .hljs-link, .hljs-symbol {
            color: #00b0e8
        }

        .hljs-emphasis {
            font-style: italic
        }

        .hljs-strong {
            font-weight: 700
        }
    </style>
</head>
<body>
    <header id="header">
        <div class="outer">
            <div class="inner">
                <div class="navi_icon icon_no_active" id="navi_icon">
                    <i class="fa fa-list"></i>
                </div>
                <h1 id="logo-wrap" style="font-size: 30px;">
                    @Model.DBName 表结构信息
                </h1>
                <span class="version_s">
                    v 1.0
                </span>
            </div>
        </div>
    </header>
    <article class="page">
        <div class="outer">
            <div id="mobile-menu-wrap"></div>
            <aside id="sidebar" class="navi_hidden">
                <strong class="sidebar-title">目录</strong>
                <a href="#dir" class="sidebar-link">数据库表目录</a>
                <strong class="sidebar-title">表结构</strong>
                @foreach (var item in Model.Tables)
                {
                    <a href="#@(item.TableName)" class="sidebar-link">@(item.TableName + " " + item.Comment) </a>
                }

                @if (Model.Views.Count > 0)
                {
                    <strong class="sidebar-title">视图</strong>
                    foreach (var item in Model.Views)
                    {
                        <a href="#@(item.Key)" class="sidebar-link">@item.Key</a>
                    }
                }

                @if (Model.Procs.Count > 0)
                {
                    <strong class="sidebar-title">存储过程</strong>
                    foreach (var item in Model.Procs)
                    {
                        <a href="#@(item.Key)" class="sidebar-link">@item.Key</a>
                    }
                }
            </aside>

            <div class="page-content" id="dir">
                <div style="padding: 20px 0; border-bottom: 1px dashed #ccc">
                    <h1 id="page-title">数据库表目录</h1>
                </div>
                <div class="page-entry">
                    <table class="tab-struct" cellspacing="0" cellpadding="5" border="1" width="100%" bordercolorlight="#D7D7E5" bordercolordark="#D3D8E0">
                        <caption>表</caption>
                        <tr bgcolor="#F0F0F0" style="font-weight: bold;"><td>序号</td><td>表名</td><td>表说明</td></tr>
                        @for (int j = 0; j < Model.Tables.Count; j++)
                        {
                            var item = Model.Tables[j];
                            <tr>
                                <td>@( j + 1 )</td>
                                <td><a href="#@(item.TableName)">@item.TableName</a></td>
                                <td>@(!string.IsNullOrWhiteSpace(item.Comment) ? item.Comment : "&nbsp;")</td>
                            </tr>
                        }
                    </table>

                    @if (Model.Views.Count > 0)
                    {
                        <table class="tab-struct" cellspacing="0" cellpadding="5" border="1" width="100%" bordercolorlight="#D7D7E5" bordercolordark="#D3D8E0">
                            <caption>视图</caption>
                            <tr bgcolor="#F0F0F0" style="font-weight: bold;"><td>序号</td><td colspan="2">视图名称</td></tr>

                            @{ var index = 1; }
                            @foreach (var item in Model.Views)
                            {
                                <tr>
                                    <td>@index</td>
                                    <td colspan="2"><a href="#@(item.Key)">@item.Key</a></td>
                                </tr>
                                index++;
                            }

                        </table>
                    }

                    @if (Model.Procs.Count > 0)
                    {
                        <table class="tab-struct" cellspacing="0" cellpadding="5" border="1" width="100%" bordercolorlight="#D7D7E5" bordercolordark="#D3D8E0">
                            <caption>存储过程</caption>
                            <tr bgcolor="#F0F0F0" style="font-weight: bold;"><td>序号</td><td colspan="2">存储过程名称</td></tr>

                            @{ var index = 1; }
                            @foreach (var item in Model.Procs)
                            {
                                <tr>
                                    <td>@index</td>
                                    <td colspan="2"><a href="#@(item.Key)">@item.Key</a></td>
                                </tr>
                                index++;
                            }

                        </table>
                    }

                </div>
            </div>

            @foreach (var item in Model.Tables)
            {
                <div class="page-content" id="@(item.TableName)">
                    <div style="font-weight: bold">
                        表名：@item.TableName
                        <a href="#dir" style="float: right;margin-top: 6px;color: #33ccff;text-decoration: none;">返回目录</a>
                    </div>
                    <div>表注释：@item.Comment</div>
                    <div class="page-entry">
                        <table class="tab-struct" cellspacing="0" cellpadding="5" border="1" width="100%" bordercolorlight="#D7D7E5" bordercolordark="#D3D8E0">
                            <tbody>
                                <tr bgcolor="#F0F0F0" style="font-weight: bold">
                                    <td>序号</td>
                                    <td>列名</td>
                                    <td>数据类型</td>
                                    <td>长度</td>
                                    <td>小数位数</td>
                                    <td>主键</td>

                                    @if (!item.DBType.StartsWith("Oracle"))
                                    {
                                        <td>自增</td>
                                    }

                                    <td>允许空</td>
                                    <td>默认值</td>
                                    <td>列说明</td>
                                </tr>

                                @foreach (var column in item.Columns)
                                {
                                    <tr class="other-bg-color">
                                        <td>@column.ColumnOrder</td>
                                        <td style="text-align: left">@column.ColumnName</td>
                                        <td>@column.ColumnTypeName</td>
                                        <td>@column.Length</td>
                                        <td>@column.Scale</td>
                                        <td>@column.IsPK</td>

                                        @if (!item.DBType.StartsWith("Oracle"))
                                        {
                                            <td>@column.IsIdentity</td>
                                        }

                                        <td>@column.CanNull</td>
                                        <td>@column.DefaultVal</td>
                                        <td>@column.Comment</td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
            }

            @if (Model.Views.Count > 0)
            {
                foreach (var item in Model.Views)
                {
                    <div class="page-content snippet" id="@(item.Key)">
                        <div style="font-weight: bold">
                            视图名称：@item.Key
                            <a href="#dir" style="float: right;color: #33ccff;text-decoration: none;">返回目录</a>
                        </div>
                        <div class="page-entry">
                            <pre><code class="language-sql hljs">@item.Value</code></pre>
                        </div>
                    </div>
                }
            }

            @if (Model.Procs.Count > 0)
            {
                foreach (var item in Model.Procs)
                {
                    <div class="page-content snippet" id="@(item.Key)">
                        <div style="font-weight: bold">
                            存储过程名称：@item.Key
                            <a href="#dir" style="float: right;color: #33ccff;text-decoration: none;">返回目录</a>
                        </div>
                        <div class="page-entry">
                            <pre><code class="language-sql hljs">@item.Value</code></pre>
                        </div>
                    </div>
                }
            }
        </div>
    </article>
    <footer id="footer">
        <a id="goto_top">
            <img src="" />
            <span class="show-txt">返回<br>顶部</span>
        </a>
        <div class="outer">
            <div id="footer-copyright">
                <div>
                    Powered By <a href="https://gitee.com/dotnetchina/DBCHM" target="_blank">DBCHM</a>
                    <div>
                        <div style="margin-top: 10px;" id="foot_show">
                            <p>版权 © 51try.top </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </footer>
    <script src="https://cdn.bootcdn.net/ajax/libs/sql-formatter/4.0.2/sql-formatter.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/highlight.js/11.0.1/highlight.min.js"></script>
    <script type="text/javascript">
        window.onload = function () {
            let arrTR = [];
            let tabs = document.getElementsByClassName("tab-struct");
            for (let j = 0; j < tabs.length; j++) {
                let tab = tabs[j];
                let trs = tab.getElementsByTagName('tr');
                for (let k = 0; k < trs.length; k++) {
                    if (k == 0) {
                        continue;
                    }
                    arrTR.push(trs[k]);
                }
            }
            for (let i = 0; i < arrTR.length; i++) {
                arrTR[i].onclick = function () {
                    for (var j = 0; j < arrTR.length; j++) {
                        arrTR[j].className = 'other-bg-color';
                    }
                    this.className = 'check-bg-color';
                }
            }

            document.getElementById("goto_top").onclick = function () {
                timer = setInterval(function () {
                    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                    var ispeed = Math.floor(-scrollTop / 6);
                    if (scrollTop == 0) {
                        clearInterval(timer);
                    }
                    document.documentElement.scrollTop = document.body.scrollTop = scrollTop + ispeed;
                }, 20)
            }

            document.getElementById("goto_top").addEventListener('mouseover', function () {
                this.getElementsByTagName("img")[0].style.display = 'none'
                this.getElementsByTagName("span")[0].style.display = 'flex'
            })

            document.getElementById("goto_top").addEventListener('mouseout', function () {
                this.getElementsByTagName("img")[0].style.display = 'block'
                this.getElementsByTagName("span")[0].style.display = 'none'
            })
            // Austin.Young add for adjust sidebar height
            setTimeout(changebleWidthHeight, 100);

            document.querySelectorAll("pre code").forEach(node => {
                var fmtSql = sqlFormatter.format(node.textContent.replace(/`/g, ""), { language: "sql", uppercase: true });
                node.textContent = fmtSql;
                hljs.highlightBlock(node);
            });
        }

        window.onscroll = function () {
            var scrollTop = document.documentElement.scrollTop;
            if (scrollTop - document.getElementById("dir").clientHeight > 0) {
                document.getElementById("goto_top").style.display = "flex"
            } else {
                document.getElementById("goto_top").style.display = "none"
            }
        }
        // Austin.Young add for adjust sidebar height
        function changebleWidthHeight() {
            var winHeight = 0;
            if (window.innerHeight)
                winHeight = window.innerHeight;
            else if ((document.body) && (document.body.clientHeight))
                winHeight = document.body.clientHeight;
            if (document.documentElement && document.documentElement.clientHeight) {
                winHeight = document.documentElement.clientHeight;
            }
            try {
                var obj = document.getElementById("sidebar");
                var objTop = obj.getBoundingClientRect().top;
                obj.style.height = (winHeight - objTop) + 'px';
            } catch (e) { }
        }
        window.onresize = changebleWidthHeight;
    </script>
</body>
</html>